<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>药品目录</title>
<link rel="stylesheet" type="text/css" href="/css/select.css" />
<script src="/jquery/jquery.min.js"></script>
<script src="/utils/TimeUtil.js"></script>
<script src="/utils/HttpUtil.js"></script>
<script>
	var global = {
		page : 1,
		size : 10,
		totalPage : 0,
		total : 0
	};
	var params = {};

	$(document).ready(function() {
		importAdmin();
		query();
	});

	function setParams() {
		params.page = global.page;
		params.size = $("#size").val();
		params.drugCode = $("#drugCode").val();
		params.drugName = $("#drugName").val();
	}

	function suss(data) {
		init();
		if (data.code == 0) {
			result = data.data;
			putSheet(result.list);
			setPage(result);
		} else {
			$("#msg").text(data.msg + "[" + data.code + "]");
		}
	}

	function err(data) {
		$("#msg").text("网络错误(" + data.status + ")")
	}

	function query() {
		setParams();
		post("/drugCatalog/select", params, suss, err);
	}

	function init() {
		$("#sheet").text("");//清空
		$("#msg").text("");
	}

	function putSheet(list) {
		var sheet = $("#sheet");
		if (list.length <= 0) {
			$("#msg").text("无数据");
			return;
		}
		for (index in list) {
			var x = list[index];
			li = "<tr>" + "<td>" + x.drugCode + "</td>" + "<td>" + x.drugName
					+ "</td>" + "<td>" + x.specification + "</td>" + "<td>"
					+ x.manufacturer + "</td>" + "<td>" + x.approvalNum
					+ "</td>" + "<td>" + x.drugStandardCode + "</td>" + "<td>"
					+ x.minUnit + "</td>" + "<td>" + x.packageUnit + "</td>"+ "<td><strong onclick='del("+x.id+")'>删除</strong></td>"
					+ "</tr>";
			sheet.append(li);
		}
	}

	function setPage(result) {
		global.page = result.page;
		global.size = result.size;
		global.totalPage = result.totalPage;
		global.total = result.total;
		setPageText();
	}

	function next() {
		if (global.page < global.totalPage) {
			global.page++;
			query();
		}
	}

	function pre() {
		if (global.page > 1) {
			global.page--;
			query();
		}
	}

	function toPage() {
		global.page = $("#toPage").val();
		query();
	}

	function setPageText() {
		$("#curPage").text(global.page);
		$("#totalPage").text(global.totalPage);
		$("#total").text(global.total);
		$("#toPage").val(global.page);
		$("#size").val(global.size);
	}

	document.onkeydown = function(event) {
		var e = event || window.event || arguments.callee.caller.arguments[0];
		if (e && e.keyCode == 13) {
			$("#query").click();
		}
	}

	function del(id) {
		if (confirm("确定删除吗?")) {
			post("/drugCatalog/delete", {
				id : id
			}, delSus, err);
		}
	}

	function delSus(data) {
		if (data.code == 0) {
			result = data.data;
			query();
		} else {
			$("#msg").text(data.msg + "[" + data.code + "]");
		}
	}

	function importAdmin() {
		$.ajax({
			url : "/template/adminInfo.html", //这里是静态页的地址
			type : "GET", //静态页用get方法，否则服务器会抛出405错误
			dataType : "html",
			success : function(data) {
				$("#admin").html(data);
			}
		});
	}
</script>
</head>
<body>
	<div id="admin"></div>
	<h1>
		<a href="/stockHome.html">首页</a>
	</h1>
	<h1>
		药品目录
		<h3>
			<a href="/file/drugCatalog/download">下载药品目录</a>&nbsp;&nbsp;&nbsp;<a
				href="/crm/drugCatalog/upload.html">上传药品目录</a>
		</h3>
		<h3>
			<a href="/file/drugMapCatalog/download">下载映射目录</a>&nbsp;&nbsp;&nbsp;<a
				href="/crm/drugMap/upload.html">上传映射目录</a>
		</h3>
	</h1>
	<h4 id="msg"></h4>
	<div id="select">
		<table>
			<tr>
				<td>药品编号:</td>
				<td><input id="drugCode" type="text"></input></td>
				<td>药品名称:</td>
				<td><input id="drugName" type="text"></input></td>
				<td><input id="query" type="button" onclick="query()"
					value="查询"></input></td>
			</tr>
		</table>
	</div>
	<div id="show">
		<table border="1">
			<thead>
				<tr>
					<th>药品编号</th>
					<th>药品名称</th>
					<th>规格</th>
					<th>厂家</th>
					<th>批准文号</th>
					<th>本位码</th>
					<th>最小单位</th>
					<th>最大单位</th>
					<th>操作</th>
				</tr>
			</thead>
			<tbody id="sheet">
			</tbody>
		</table>
	</div>
	<div id="page">
		<p>
			<strong onclick="pre()">上一页</strong> <strong>当前[<i
				id="curPage">1</i>]页
			</strong> <strong onclick="next()">下一页</strong> <strong>共[<i
				id="totalPage">1</i>]页
			</strong> <strong><i onclick="toPage()">跳转</i><input id="toPage"
				type="number" min="1" style="width: 30px;"></input>页</strong> <strong>每页<input
				id="size" type="number" min="1" value="10" style="width: 30px;"></input>条
			</strong> <strong>共[<i id="total">1</i>]条数据
			</strong>
		</p>
	</div>
</body>
</html>